class Solution {
public:
    vector<vector<int>> divideArray(vector<int>& a, int k) {
        sort(a.begin(), a.end());
        int n = a.size();
        if (n % 3)return {};
        vector<vector<int>> ans;
        for (int i = 0; i < n; i += 3) {
            if (a[i + 2] - a[i] <= k) ans.push_back({ a[i],a[i + 1],a[i + 2] });
            else return {};
        }
        return ans;
    }
};